<?php
/**
 *
 * Страница прохождение и просмотра результатов теста
 *
 * @package zfhrtool
 * @subpackage View
 */
$this->headTitle($this->translate('[LS_PAGE_TITLE_TESTS]'));
?>
<?php if (isset($this->objForm)): ?>
<script type="text/javascript" language="javascript">
<!--
//<![CDATA[
    var min = <?=$this->time?>;
    var sec = 00;
    function timer()
    {
        if( !((sec == 0) && (min == 0))) {            
            if(sec == 0) {
                sec = 60;
                min -= 1;
            }
            sec -= 1;
            document.getElementById("timer").innerHTML = min + ':' + (sec<10?'0'+sec:sec);
            window.setTimeout("timer()", 1000);
        } else {
            document.getElementById("send").form.submit();
        }
    }
    window.setTimeout('timer()', 1000);
//]]>
-->
</script>
<?php endif;?>


<div id="main">
<?php if (isset($this->sendTest)): ?>
    <h1>
    Спасибо за пройденный тест :)
    </h1>
<?php else: ?>
    <?php if ( !isset( $this->objForm ) && !isset( $this->score)): ?>
    <div class="menu-h f-right">
    <ul>
        <li><a href="<?=$this->url(array('controller' => 'test', 'action' => 'recalc'))?>">Пересчет результата теста</a></li>
    </ul>
    </div>
    <?php endif ?>
    <h1 class="title" style="display:inline; border:0">ФИО: <?php echo $this->applicantName; ?></h1>
    <br />
    <h1 class="title" style="display:inline; border:0">Тест: <?php echo $this->testName; ?></h1>
    <br />
    <?php if (isset($this->objForm)): ?>
    <h1 class="title" style="display:inline; border:0">До конца теста осталось: <font id="timer" color=#FF0000>00:00</font></h1>
    <br /><br />
    <?php else: ?>
    <h1 class="title" style="display:inline; border:0">Результат:</h1>
        <?php if ( $this->score ):?>
        <h3>Набрано баллов: <?php echo $this->score; ?></h3>
        <h3>Процент от максимального: <?php echo $this->percent; ?>%</h3> 
        <?php else: ?>
       <h3>Процент правильных ответов: <?php echo $this->percent; ?>%</h3>
        <?php endif;?> 
    <?php endif; ?>
    <div class="z_form">
    <?php if (isset($this->objForm)): ?>
        <?php echo $this->objForm; ?>
    <?php else: ?>
    <?php //print_r($this->failAnswerQuestions);print_r($this->newRows);die; ?>
    Количество вопросов: <?php echo (int) $this->countQuestions; ?><br />
    Неверных ответов: <?php echo $this->countQuestionFail; ?><br /><br />
    <?php if ( $this->questionCategories ):?>
    <p>Процент набранных баллов в каждой категории:</p>
    <ol>
        <?php foreach ( $this->questionCategories as $name => $score ):?>
            <li><?php echo $this->escape( $name ); ?>
                &nbsp;&ndash;&nbsp;
                <?php echo $this->escape( $score ); ?>%
            </li>
        <?php endforeach; ?>
    </ol>
    <?php endif; ?>
        
    <?php foreach ( $this->questionsAndAnswers as $question ): ?>
        <p class="question">
        <?php switch ( $question['state'] ): 
                  case 0:?>
                <span class="wrong">
            <?php break;?>
            <?php case 1:?>
                <span class="halfright">
            <?php break;?>
            <?php case 2:?>
                <span class="right">
            <?php break;?>
        <?php endswitch;?>
        <?php echo $this->escape($question['text'])?></span>
        </p>
        <?php if ( $question['state'] < 2 ):?>
            <ul>
            <?php foreach ( $question['answers'] as $answer ):?>
                <li>
                <?php if ( $answer['state'] ):?>
                 	<img src="<?=$this->baseUrl().'/images/ch_tick.gif'?>" title="Выбран" class="img_doing" />
                <?php else:?>
                    <img src="<?=$this->baseUrl().'/images/ch_cross.gif'?>" title="Не выбран" class="img_doing" />
                <?php endif;?>
                <?php if ( $answer['flag'] ):?>
                    <span class="right">
                <?php else :?>
                   <span class="wrong">
                <?php endif;?>
                <?php echo $this->escape($answer['text'])?></span>
                </li>
            <?php endforeach;?>
            </ul>
        <?php endif;?>
    <?php endforeach;?>
    <?php endif ?>
	</div>
<?php endif ?>
</div>